package com.mongo.pattern;

/**
 * @author: simon
 * @date: 2019/8/5 16:49
 */
public class BookShelf implements Aggregate {

    private Book[] books;

    private int lastIndex;

    public BookShelf(int size) {
        books = new Book[size];
    }

    public void addBook(Book book){
        books[lastIndex] = book;
        lastIndex++;
    }

    public int getLastIndex() {
        return lastIndex;
    }

    public Book getBookAtIndex(int index){
        return books[index];
    }

    @Override
    public Iterator iterator() {
        return new BookShelfIterator(this);
    }
}
